package cn.wwcyc.exception;

import cn.wwcyc.domain.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    private Logger logger = LoggerFactory.getLogger("统一异常处理日志");

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Object handleException(Exception e) {
        logger.error("系统异常", e);
        return R.error(WWExceptionEnum.SYSTEM_ERROR);
    }

    @ExceptionHandler(WWException.class)
    @ResponseBody
    public Object handleWWException(WWException e) {
//        if(e.code == WWExceptionEnum.ZB_NO_FILE.code){
//            System.out.println(e.message);
//            throw new RuntimeException(e.message);
//        }
        return R.error(e.getCode(), e.getMessage());
    }
}
